package com.wind.devlop.module2;

import com.wind.common.config.RuoYiConfig;
import com.wind.common.core.domain.AjaxResult;
import com.wind.common.utils.file.FileUploadUtils;
import com.wind.common.utils.file.FileUtils;
import com.wind.framework.config.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author chen0
 * @version 1.0
 * @description: TODO
 * @date 2023/5/16 19:27
 */
@RestController
public class FileUploadController {

    @Autowired
    private ServerConfig serverConfig;

//    @PostMapping("/devlop/uploadFileUrl")
//    public AjaxResult uploadFile(MultipartFile file) throws Exception
//    {
//        try
//        {
//            // 上传文件路径
//            String filePath = RuoYiConfig.getUploadPath();
//            // 上传并返回新文件名称
//            String fileName = FileUploadUtils.upload(filePath, file);
//            String url = serverConfig.getUrl() + fileName;
//            AjaxResult ajax = AjaxResult.success();
//            ajax.put("url", url);
//            ajax.put("fileName", fileName);
//            ajax.put("newFileName", FileUtils.getName(fileName));
//            ajax.put("originalFilename", file.getOriginalFilename());
//            return ajax;
//        }
//        catch (Exception e)
//        {
//            return AjaxResult.error(e.getMessage());
//        }
//    }
}
